<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #btn {
            width: 50px;
            height: 23px;
            background: skyblue;
            vertical-align: middle;
        }
    </style>
</head>

<body>
    用户名：<input type="text" id="userName" name="" id="">
    密码：<input type="password" id="passWord" name="" id="">
    验证码：<input type="text" name="" id="yzm">
    <button id="btn"></button>

    <script>
        var random = parseInt(Math.random() * (8999 + 1) + 1000)
        btn.innerHTML = random
        btn.onclick = function () {
            random = parseInt(Math.random() * (8999 + 1) + 1000)
            btn.innerHTML = random
        }

        yzm.onchange = function () {
            if (yzm.value == random) {
                alert('登录成功')
            } else {
                alert('验证码错误，请重新输入')
                random = parseInt(Math.random() * (8999 + 1) + 1000)
                btn.innerHTML = random
            }
        }
    </script>

</body>

</html>